package Shopping;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Connect {
	private Connection ct = null;
	private PreparedStatement ps = null;
	private ResultSet rs = null;
	
	private static String URL = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false";
	private static String driverName = "com.mysql.jdbc.Driver";
	private static String userName = "root";
	private static String password = "ty123456";
	
	public Connection getConn(){
		try {
			Class.forName(driverName);
			ct = DriverManager.getConnection(URL, userName, password);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ct;
	}
	
	public void closeDBResource() {
		try {
			if (rs != null) {
				rs.close();
				rs = null;
			}
		} catch (Exception e2) {
			e2.printStackTrace();
			
		}
		try {
			if (ps != null) {
				ps.close();
				ps = null;
			}
		} catch (Exception e2) {
			e2.printStackTrace();
		}
		try {
			if (ct != null) {
				ct.close();
				ct = null;
			}
		} catch (Exception e2) {
			e2.printStackTrace();
		}
	}

}
